<template>
  <uni-page-wrapper>
    <uni-page-body>
      <uni-view class="loginBg">
        <uni-view class="container">
          <uni-view class="formItem">
            <uni-input class="input">
              <div class="uni-input-wrapper">
                <input
                  :placeholder='$t("register.please enter user name")'
                  maxlength="140" 
                  step=""
                  enterkeyhint="done"
                  autocomplete="off"
                  type=""
                  class="uni-input-input"
                  :value="username"
                  @input="onKeyInput('username', $event)"
                />
              </div>
            </uni-input>
          </uni-view>
          <uni-view class="formItem">
            <uni-input class="input">
              <div class="uni-input-wrapper">
                <input
                  :placeholder='$t("register.Please enter tel")'
                  maxlength="140"
                  step="0.000000000000000001"
                  enterkeyhint="done"
                  autocomplete="off"
                  type="number"
                  class="uni-input-input"
                  :value="tel"
                  @input="onKeyInput('tel', $event)"
                />
              </div>
            </uni-input>
          </uni-view>
          <uni-view class="formItem">
            <uni-input class="input">
              <div class="uni-input-wrapper">
                <input
                  :placeholder='$t("register.Please enter login password")'
                  maxlength="140"
                  step=""
                  enterkeyhint="done"
                  autocomplete="off"
                  type="password"
                  class="uni-input-input"
                  :value="password"
                  @input="onKeyInput('password', $event)"
                />
              </div>
            </uni-input>
          </uni-view>
          <uni-view class="formItem">
            <uni-input class="input">
              <div class="uni-input-wrapper">
                <input
                  :placeholder='$t("register.Please enter transaction password")'
                  maxlength="140"
                  step=""
                  enterkeyhint="done"
                  autocomplete="off"
                  type="password"
                  class="uni-input-input"
                  :value="jypassword"
                  @input="onKeyInput('jypassword', $event)"
                />
              </div>
            </uni-input>
          </uni-view>
          <uni-view class="formItem">
            <uni-input class="input">
              <div class="uni-input-wrapper">
                <input
                  :placeholder='$t("register.Please enter the invite code")'
                  maxlength="140"
                  step=""
                  enterkeyhint="done"
                  autocomplete="off"
                  type=""
                  class="uni-input-input"
                  :value="lvid"
				  :disabled="lviddisabled"
                  @input="onKeyInput('lvid', $event)"
                />
              </div>
            </uni-input>
          </uni-view>
          <uni-view class="submitBtn" @click="submit">{{$t('register.Submit')}}</uni-view>
          <uni-view class="other">
            <uni-view class="item" @click="toSignin"
              >{{$t('register.Already have an account? Sign in now')}}</uni-view
            >
          </uni-view>
        </uni-view>
      </uni-view>
    </uni-page-body>
  </uni-page-wrapper>
</template>

<script>
import service from '@/store/service.js'
export default {
  data() {
    return {
      username: "",
      tel: "",
      password: "",
      jypassword: "",
      lvid: "",
	  lviddisabled:false,
	  issub:false
    };
  },
  onLoad(options){
	this.lvid = options.id
	this.lviddisabled = options.id ? true:false
  },
  methods: {
    onKeyInput(type, event) {
      this[type] = event.target.value;
    },
    toSignin() {
      uni.redirectTo({
        url: "/pages/login/login",
      });
    },
    submit() {
		if(this.issub){
			return
		}
		this.issub = true
        uni.showLoading();
		service.normal(this,service.api.app_register,{
			username:this.username,
			tel:this.tel,
			password:this.password,
			jypassword:this.jypassword,
			lvid:this.lvid
		},function(self,res){
			self.issub = false
			uni.setStorageSync('token',res.token)
			//调用注册接口，成功后跳转到主页
			uni.hideLoading();
			uni.reLaunch({
			  url: "/pages/home/home",
			});
		})
    },
  },
};
</script>

<style>
@import url(./register.css);
</style>